package org.cloudnote.service.impl;

import org.cloudnote.bean.NoteBook;
import org.cloudnote.mapper.NoteBookMapper;
import org.cloudnote.service.NoteBookService;
import org.cloudnote.util.NoteUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NoteBookServiceImpl implements NoteBookService {

    @Autowired
    private NoteBookMapper noteBookMapper;
    @Override
    public List<NoteBook> getByUserId(String userId) {
        List<NoteBook> noteBooks = noteBookMapper.selectByUserId(userId);
        return noteBooks;
    }

    @Override
    public int save(NoteBook noteBook) {
        noteBook.setUserId(noteBook.getUserId());
        noteBook.setNoteBookId(NoteUtil.createId());
        noteBook.setNoteBookName(noteBook.getNoteBookName());
        noteBook.setNoteBookTypeId(5+"");
        noteBook.setNoteBookCreateTime(LocalDateTime.now()+"");
        noteBook.setNoteBookDesc(noteBook.getNoteBookDesc());
        int count = noteBookMapper.save(noteBook);
        return count;
    }
}
